import { getExam, addExam, delexam } from '@/api/exam'

let state = {
  examlist: [],
  classify: [],
  serch: "",
  total: 0,
  currentPage: 1,
  pageSize: 10,
}

let mutations = {
  SET_EXAM(state, res) {
    state.examlist = res.data,
      state.total = res.total
  },
  SET_CURRENT(state, page) {
    state.currentPage = page
  },
  SET_PAGESIZE(state, page) {
    state.pageSize = page
  },
  SET_SEARCH(state, search) {
    state.serch = search
  }
}

let actions = {
  async getExamlist({ commit, state }) {
    let data = await getExam({
      curr: state.currentPage - 1,
      pageSize: state.pageSize,
      serch: state.serch,
    })
    commit("SET_EXAM", data)
  },
  async sendExam({ dispatch }, data) {
    console.log(data);
    await addExam(data)
    dispatch("getExamlist")
  },
  async deletExam({ dispatch }, id) {
    await delexam(id)
    dispatch("getExamlist")
  }
}

let getters = {}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}